package io.netty.example.http.websocketx.benchmarkserver;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

/**
 * @author sunzhuang
 * @date 2022年03月19日 6:49 PM
 */
public class ServerSocketClientTest {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);

        Socket socket = new Socket("localhost", 8081);
//        SocketChannel channel = socket.getChannel();
        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        while (true) {
            String nextLine = scanner.nextLine();
            System.out.println(nextLine);
            byte[] bytes = nextLine.getBytes();
            int read = inputStream.read(bytes);
            byte[] byteReader = new byte[16];
            int a = 0;
            outputStream.write(byteReader, a * byteReader.length, (a + 1) * byteReader.length);
            System.out.println(new String(byteReader));
            if ("done".equals(nextLine)) {
                break;
            }
        }


    }

}
